<?php
session_start();
require_once ( 'inc/function.php' );

$smarty = new Smarty;

$DB = NewADOConnection('mysql');
$DB->Connect('localhost', $sql_user, $sql_pass, $sql_dbase);

$login = $_SESSION['login'];

log_check($login);


if(array_key_exists('submit', $_POST)){

  $add_login = $_POST['login'];
  $add_pass = $_POST['pass'];
  $add_pass2 = $_POST['pass2'];

  // echo "$add_login, $add_pass, $add_pass2";

  if ($add_pass!=$add_pass2){
    $smarty->assign('info', "Passwords are different");
    $self = basename($_SERVER['PHP_SELF']);
    $smarty->assign('self', $self);
    $smarty->display('add_account.tpl');
    die();
  }

  if ($add_login=="" OR $add_pass=="" OR $add_pass2==""){
    $smarty->assign('info', "Empty input field");
    $self = basename($_SERVER['PHP_SELF']);
    $smarty->assign('self', $self);
    $smarty->display('add_account.tpl');
    die();
  }

  $smarty->assign('info', "Done");
  $add_pass = md5($add_pass);
  $auth = $DB->GetOne("INSERT INTO users (login, pass) VALUES('$add_login' , '$add_pass') ");

}

$self = basename($_SERVER['PHP_SELF']);
$smarty->assign('self', $self);
$smarty->display('add_account.tpl');

?>